define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'clue/index' + location.search,
                    add_url: 'clue/add',
                    edit_url: 'clue/edit',
                    del_url: 'clue/del',
					import_url: 'clue/import',
                    table: 'clue',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
				searchFormVisible: true,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('ID'), sortable: true, searchable:false},
                        {field: 'companyname', title: __('公司名称'), operate: 'LIKE'},
                        {field: 'cluecontent', title: __('线索情况'), operate: 'LIKE'},
						{field: 'telephone', title: __('联系电话'), operate: 'LIKE'},
						{field: 'admin_id', title: __('开发人'), addClass: "selectpage", extend: "data-source='auth/admin/index' data-field='nickname'", formatter:function(value, row, index){
							return row.admin.nickname;
						}},
						{field: 'developtime', title: __('开发时间'), formatter: Table.api.formatter.datetime, datetimeFormat:'YYYY-MM-DD', operate: 'RANGE', addclass: 'datetimerange', sortable: true},
						{field: 'isdeal', title: __('是否成交'), searchList:{1:'是', 0:'否'}, formatter: Table.api.formatter.label},
						{field: 'amount', title: __('成交金额'), operate: 'BETWEEN'},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                $(document).on('click','button[type="reset"]', function(){
					var index = parent.Layer.getFrameIndex(window.name);
					parent.Layer.close(index);
				});
				
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});